<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>
<script type="text/javascript" charset="utf-8">
	var datagrid;
	var auth = "${auths}";
	var buttons = [];
	$(function() {
		if(auth=="all"){
			buttons.push({text : '编辑',iconCls : 'icon-edit',handler : function() {edit();}});
			buttons.push('-');
			buttons.push({text : '取消选中',iconCls : 'icon-undo',handler : function() {datagrid.datagrid('clearSelections');datagrid.datagrid('unselectAll');}});
			buttons.push('-');
		}else if(auth!=""){
			var auths = auth.split(",");
			if(auths.length>0){
				for(var i=0;i<auths.length;i++){
					 if(auths[i]=="XSGL_JFCL_EDIT"){
						buttons.push({text : '编辑',iconCls : 'icon-edit',handler : function() {edit();}});
						buttons.push('-');
					}
				}
				buttons.push({text : '取消选中',iconCls : 'icon-undo',handler : function() {datagrid.datagrid('clearSelections');datagrid.datagrid('unselectAll');}});
				buttons.push('-');
			}
		}

	
		datagrid = $('#datagrid').datagrid({
			url : 'pointTacticsAction!datagridPointTactics.html',
			title : '编辑经销商积分策略',
			iconCls : 'icon-save',
			pagination : true,
			pagePosition : 'bottom',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40 ],
			fit : true,
			fitColumns : false,
			nowrap : false,
			border : false,
			idField : 'id',
			sortName : 'id',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : false,
			singleSelect : true,
			//onLoadSuccess:function(data){
				//alert(data[0]);
			//},
			columns : [ [
			{
				title : '编号',
				field : 'id',
				width : 150,
				sortable : true,
				checkbox : true
			}, {
				title : '经销商姓名',
				field : 'username',
				width : 150,
				sortable : true
			},{
				title : '所属角色',
				field : 'roname',
				sortable : true,
				width : 150
			}, {
				title : '金额积分换算比例',
				field : 'moneyPointProp',
				sortable : true,
				width : 150
			} , {
				title : '积分抵现比例',
				field : 'pointMoneyProp',
				sortable : true,
				width : 150
			}, {
				title : '积分抵现基数',
				field : 'pointDeductionBase',
				sortable : true,
				width : 150
			}]],
			toolbar : buttons,
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$(this).datagrid('unselectAll');
				$(this).datagrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}
		});

	});

	function edit() {
		var rows = datagrid.datagrid('getSelections');
		if (rows.length == 1) {
			var p = parent.sy.dialog({
				title : '编辑积分策略',
				href : '${pageContext.request.contextPath}/xsgl/pointTacticsAction!pointTacticsEdit.html',
				width : 320,
				height : 170,
				buttons : [ {
					text : '编辑',
					handler : function() {
						var f = p.find("#userForm");
						f.form('submit', {
							url : '${pageContext.request.contextPath}/xsgl/pointTacticsAction!edit.html',
							success : function(d) {
							//alert(d);
								var json = $.parseJSON(d);
								if (json.success) {
									datagrid.datagrid('reload');
									p.dialog('close');
								}
								parent.sy.messagerShow({
									msg : json.msg,
									title : '提示'
								});
							}
						});
					}
				} ],
				/* onLoad : function() {
					var f = p.find('form');
					var roleIds = f.find('input[name=roleIds]');
					var roleIdsCombobox = roleIds.combobox({
						url : '${pageContext.request.contextPath}/demo/roleAction!doNotNeedSession_combobox.action',
						valueField : 'cid',
						textField : 'cname',
						multiple : true,
						editable : false,
						panelHeight : 'auto',
						onLoadSuccess : function() {
							parent.$.messager.progress('close');
						}
					});
					f.form('load', {
						cid : rows[0].cid,
						cname : rows[0].cname,
						roleIds : sy.getList(rows[0].roleIds),
						ccreatedatetime : rows[0].ccreatedatetime,
						cmodifydatetime : rows[0].cmodifydatetime
					});
				} */
			});
		} else if (rows.length > 1) {
			parent.sy.messagerAlert('提示', '同一时间只能编辑一条记录！', 'error');
		} else {
			parent.sy.messagerAlert('提示', '请选择要编辑的记录！', 'error');
		}
	}
</script>
</head>
<body class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false" style="overflow: hidden;">
		<table id="datagrid"></table>
	</div>

	<div id="menu" class="easyui-menu" style="width:120px;display: none;">
		<div onclick="edit();" data-options="iconCls:'icon-edit'">编辑</div>
	</div>
</body>
</html>